package com.example.a22310.myapplication.Activity;
//红色的R解决不了

import android.content.Context;
import android.content.SharedPreferences;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;

import com.example.a22310.myapplication.ViewModel.Attention.AtttentionViewModel;
import com.example.a22310.myapplication.databinding.ActivityAttentionBinding;

public class AttentionActivity extends AppCompatActivity {
    private String FILENAME = "yuejian'data";
    private ActivityAttentionBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_attention);
        initialize();
    }
    private int  getUserid(){
        int newsNumber;
        SharedPreferences sharedPreferences = getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
        newsNumber = sharedPreferences.getInt("userId",0);
        return newsNumber;
    }

    private void initialize(){
        binding.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                switch (i){
                    case 0:
                        new AtttentionViewModel(AttentionActivity.this,binding,getUserid(),1);
                        break;
                    case 1:
                        new AtttentionViewModel(AttentionActivity.this,binding,getUserid(),0);
                        break;
                    default:
                        break;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }

}
